package org.jtb.quickr;

import java.io.File;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import org.apache.commons.httpclient.methods.multipart.Part;

class PhotosAddTagsRequest extends SignedMethodRequest {
    private static Logger logger = Logger.getLogger(PhotosAddTagsRequest.class.getName());
    
    private String photoId;
    private Set<String> tags;
    
    protected PhotosAddTagsRequest(String baseUrl, String apiKey, String secret, AuthResponse.Token authToken, String photoId, Set<String> tags) {
        super(baseUrl, apiKey, secret, authToken, "flickr.photos.addTags");
        
        this.photoId = photoId;
        this.tags = tags;
    }
    
    protected Map<String,String> getArgs() {
        putArg("photo_id", photoId);
        putArg("tags", join(tags, ' '));
        
        return super.getArgs();
    }
    
    public EmptyReponse execute() throws QuickrException {
        FlickrUrl furl = new PostUrl(getBaseUrl(), getArgs(), getApiKey(), getSecret(), getAuthToken());
        Map<String,String> args = furl.getArgs();
        Map<String,Object> params = new HashMap<String,Object>(args);
        
        HttpVerb post = new Post(furl.getUrl(), params);
        InputStream is = post.execute();
        
        EmptyReponse nr = new EmptyReponse(is);
        return nr;
    }
}
